package com.zhongketech.sunflower.activity;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.provider.MediaStore;
import android.provider.MediaStore.Video.Thumbnails;
import android.support.v4.view.ViewPager;
import android.text.ClipboardManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zhongketech.sunflower.Constant;
import com.zhongketech.sunflower.MyApplication;
import com.zhongketech.sunflower.MyToast;
import com.zhongketech.sunflower.R;
import com.zhongketech.sunflower.adapter.ExpressionAdapter;
import com.zhongketech.sunflower.adapter.ExpressionPagerAdapter;
import com.zhongketech.sunflower.adapter.FcsContact;
import com.zhongketech.sunflower.adapter.FcsContactAdapter;
import com.zhongketech.sunflower.adapter.MessageAdapter;
import com.zhongketech.sunflower.adapter.VoicePlayClickListener;
import com.zhongketech.sunflower.transport.Action;
import com.zhongketech.sunflower.transport.LogUtil;
import com.zhongketech.sunflower.transport.im.ZKSocket;
import com.zhongketech.sunflower.transport.model.Authorizations;
import com.zhongketech.sunflower.transport.model.MyRequest;
import com.zhongketech.sunflower.transport.model.Parents;
import com.zhongketech.sunflower.transport.model.Request;
import com.zhongketech.sunflower.transport.model.User;
import com.zhongketech.sunflower.utils.CommonUtils;
import com.zhongketech.sunflower.utils.ImageUtil;
import com.zhongketech.sunflower.utils.SmileUtils;




/**
 * 绑定界面
 * 
 */
public class ParentsActivity extends BaseActivity  {


	private static final String TAG = "ParentsActivity";

	private ListView listView ;
	private Context context;


	private List<FcsContact> myData = new ArrayList<FcsContact>();
	private Handler handler ;
	private FcsContactAdapter adapter;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fcs_contacts_activity);
		context = this;
		initView();

		handler = new Handler() {
			public void handleMessage(Message msg) {
				adapter.notifyDataSetChanged();
			}
		};
		
		initData();
	}


	@Override  
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(KeyEvent.KEYCODE_BACK == keyCode)
		{
			back();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	private void initData()
	{

		new Thread(new Runnable() {
			public void run() {
				Looper.prepare();

				Parents parents = new Action().myParents();
				if(null != parents)
				{	
					if(null == parents.getParents() || 
							parents.getParents().size() == 0)
					{
						LogUtil.i(TAG,"没有相关的绑定信息");
					}
					else
					{
						for(int i = 0; i < parents.getParents().size();i ++)
						{
							FcsContact ad = new FcsContact();
							String avUrl = parents.getParents().get(i).getAvatar_url();
							if(null != avUrl && !avUrl.startsWith("http"))
							{
								avUrl = Constant.IMGAGE_SERVER + avUrl;
							}
							ad.imageUrl = avUrl;
							ad.imageViewId = R.drawable.default_contacts_head;
							ad.itemText = parents.getParents().get(i).getName();
							ad.statusText = "";
							ad.textview2 = null;
							myData.add(ad);

							final Message msg = new Message();
							handler.sendMessage(msg);
						}
					}
					
					
				}
				else
				{
					LogUtil.i(TAG,"无法获取到绑定信息");
				}
			}
		}).start();


	}

	private void initView()
	{
		((TextView) findViewById(R.id.title)).setText("家长");
		listView = (ListView) findViewById(R.id.listView);
		adapter = new FcsContactAdapter(myData,Constant.FCS_ADAPTER_TYPE_BIND);
		listView.setAdapter(adapter);
	}


	private void back()
	{
		finish();
	}

}
